package com.joysuch.wwyt.api.alarmbluetooth.utils;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;


public class NamedThreadFactory implements ThreadFactory {

    private AtomicInteger threadIdx;
    private String prefix;

    public NamedThreadFactory(String prefix) {
        this.threadIdx = new AtomicInteger(0);
        this.prefix = prefix;
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread t = new Thread(r);
        t.setName(prefix + "-" + threadIdx.getAndIncrement());
        return t;
    }
}
